package com.dgut.service.impl;

import com.dgut.dao.IAccountDao;
import com.dgut.domain.Account;
import com.dgut.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements IAccountService {

    @Autowired
    private IAccountDao accountDao;

    @Override
    public void trans(String from, String to, float money) {
        Account fromAccount = accountDao.findAccountByName(from);
        Account toAccount = accountDao.findAccountByName(to);

        fromAccount.setMoney(fromAccount.getMoney() - money);
        accountDao.updateAccount(fromAccount);

        toAccount.setMoney(toAccount.getMoney() + money);
        accountDao.updateAccount(toAccount);

    }
}
